package com.hs.egova.controller;

import com.hs.egova.util.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author husheng
 * @version v1.0
 * @date 2021/7/23 16:11
 * @email husheng@egova.com.cn
 */
@RestController
@RequestMapping("/redis")
@Api(tags = "redis相关操作")
public class RedisController {

    @Autowired
    private RedisUtil redisUtil;

    @ApiOperation("设置值")
    @PostMapping("/set")
    public boolean redisSet(String key, String value) {
        return redisUtil.set(key, value);
    }

    @ApiOperation("获取值")
    @GetMapping("/get")
    public Object redisGet(String key) {
        return redisUtil.get(key);
    }

    @ApiOperation("设置过期时间")
    @GetMapping("/expire")
    public boolean expire(String key) {
        int expireTime = 60;
        return redisUtil.expire(key, expireTime);
    }
}
